const http = uni.$u.http
export default {
  /**
   * 政策配置
   */
    // TODO
    getPolicyList: (data) => http.get('/core/agreement-config/listByType', data),
    getPolicyDetail: (data) => http.get('/core/agreement-config/get', data),
    getConfig: (data) => http.get('/core//param-config/getByCode', data),
    getNoticePage: (data) => http.get('/core/appNotice/get', data),
    // TODO
    updateMemberInfo: (data) => http.post('/member/social-user/update', data),
    /**
     * 登录
     */
    wxlogin: (data) => http.post('/member/auth/weixin-mini-app-login', data),
    getState: (data) => http.get('/member/auth/social-auth-redirect', data),
    getMemberInfo: () => http.get('/member/auth/get', { type: 34 }),
    /**
     * 首页
     */
    // 充电站列表,根据定位
    getChargeStationList: (data) => http.post('/core/appIndex/getStationList', data),
    /**
     * 钱包
     */
    // 充值
    recharge: (data) => http.post('/core/wechat/pay/createOrder', data),
    // 获取钱包
    getBalance: () => http.get('/core/appBalance/get'),

    /**
     * 充电
     * TOP_UP("top_up", "预付款支付"),
     * ORDER_TOP_UP("order_top_up", "余额充值支付"),
     * PAY("pay", "支付"),
     * RENEWAL("renewal","续充"),
     * REFUND("refund","退款"); core/wechat/pay/createOrder
     */
    getOrderStatus: (data) => http.get('/core/appOrder/getOrderStatus', data),
    getOrderDetail: (data) => http.get('/core/appOrder/getOrderDetail', data),
    closeOrder: (data) => http.post('/core/appOrder/endOfCharging', data),
    getOrderPage: (data) => http.post('/core/appOrder/getOrderList', data),


  /**
   * 业务接口
   */
  // wxMenu列表
  getWxMenuList: (data) => http.get('/wxMenu/list', data),
  // banner列表
  getWxBannerList: (data) => http.get('/wxBanner/list', data),
  // 房屋列表
  getOfficeBuildingPage: (data) => http.get('/officeBuilding', data),
  getOfficeBuildingTemplateList: (data) => http.get('/officeBuildingTemplate/list', data),
  // 写字楼详情
  getOfficeBuildingDetail: (id) => http.get('/officeBuilding/' + id),
  getOfficeBuildingTemplateDetail: (id) => http.get('/officeBuildingTemplate/' + id),

  /**
   * 办公用品商城
   */
  // 商品分类
  getOfficeCategoryTree: (data) => http.get('/officeCategory/tree', data),
  getOfficeCategoryList: () => http.get('/officeCategory/list'),

  // 商品管理
  getOfficeProductList: (data) => http.get('/officeProduct', data),
  getOfficeProduct: (id) => http.get('/officeProduct/' + id),

  // 订单管理
  getOfficeOrderList: (data) => http.get('/officeOrder/list', data),
  getOfficeOrder: (id) => http.get('/officeOrder/' + id),
  createOfficeOrder: (data) => http.post('/officeOrder', data),
  cancelOfficeOrder: (data) => http.post('/officeOrder/cancel', data),

  // 微信支付相关
  createWxPayment: (data) => http.post('/officeOrder/createWxPayment', data),
  queryWxPayment: (data) => http.get('/officeOrder/queryWxPayment', data),

  // 退款管理
  getOfficeOrderRefundByOrder: (data) => http.get('/officeOrderRefund/listByOrder', data),
  
  /**
   * 桶装水商城
   */
  // 商品分类
  getWaterCategoryTree: (data) => http.get('/officeCategory/tree', data),

  // 商品管理
  getWaterProductList: (data) => http.get('/officeProduct', data),
  getWaterProductDetail: (data) => http.get('/officeProduct/' + data.id),
  
  /**
   * 地址管理
   */
  // 获取用户地址列表
  getUserAddressList: (data) => http.get('/address/user', data),
  // 获取默认地址
  getDefaultAddress: (data) => http.get('/address/getDefault', data),
  // 添加地址
  addAddress: (data) => http.post('/address', data),
  // 更新地址
  updateAddress: (id, data) => http.put(`/address/${id}`, data),
  // 设置默认地址
  setDefaultAddress: (data) => http.post('/address/setDefault', data),
  // 删除地址
  deleteAddress: (id) => http.delete(`/address/${id}`),

  /**
   * 用户管理
   */
  // 用户登录
  login: (data) => http.post('/member/login', data),
  // 微信登录
  wechatLogin: (data) => http.post('/member/wechatLogin', data),
  // 用户注册
  register: (data) => http.post('/member/register', data),
  // 获取用户信息
  getUserInfo: () => http.get('/member/info'),
  // 更新用户信息
  updateUserInfo: (data) => http.put('/member/updateInfo', data),
  // 上传文件
  uploadFile: (filePath, name = 'file') => {
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: uni.$u.http.config.baseUrl + '/upload/file',
        filePath: filePath,
        name: name,
        header: {
          Authorization: 'Bearer ' + uni.getStorageSync('token')
        },
        success: (res) => {
          try {
            const data = JSON.parse(res.data);
            if (data.code === 200) {
              resolve(data.data);
            } else {
              reject(data);
            }
          } catch(e) {
            reject(e);
          }
        },
        fail: (err) => {
          reject(err);
        }
      });
    });
  },
  /**
   * 订单管理
   */
  // 创建订单
  createOrder: (data) => http.post('/order', data)
}
